package com.feishu.conntroller;



import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.feishu.service.FeiShuCommonService;
import com.hustcad.plm.pdm.ec.module.dto.TyplmFlowTaskInfoDTO;
import com.hustcad.plm.pdm.ec.module.vo.ChgFormVO;
import com.hustcad.plm.pdm.ec.service.TyplmEngineeringChangeService;
import com.hustcad.plm.pdm.enumeration.model.dto.EnumerationValueDTO;
import com.hustcad.plm.pdm.enumeration.model.vo.EnumerationItemHandleVO;
import com.hustcad.plm.pdm.enumeration.model.vo.EnumerationQueryVO;
import com.hustcad.plm.pdm.enumeration.service.TyplmEnumerationItemService;
import com.hustcad.plm.pdm.enumeration.service.TyplmEnumerationService;
import com.hustcad.plm.pdm.flowbusiness.model.entity.FlowObject;
import com.hustcad.plm.pdm.flowbusiness.model.entity.WorkFlowObjectPackage;
import com.hustcad.plm.pdm.form.model.vo.TyplmFormDataVO;
import com.hustcad.plm.pdm.form.service.TyFormDataExtService;
import com.hustcad.plm.pdm.partbom.service.TyplmPartService;
import com.hustcad.plm.pdm.partbom.vo.PartDetailsVO;
import com.hustcad.plm.pdm.redislock.TyplmRedisLockService;
import com.hustcad.plm.pdm.workflow.model.constant.WorkFlowErrorCodeEnum;
import com.hustcad.plm.pdm.workflow.model.entity.FlowTaskInfo;
import com.hustcad.plm.pdm.workflow.model.entity.Router;
import com.hustcad.plm.pdm.workflow.model.entity.WorkFlowContainerView;
import com.hustcad.plm.pdm.workflow.service.TyplmWorkFlowContainerService;
import com.hustcad.plm.pdm.workflow.service.TyplmWorkFlowProcessService;
import com.hustcad.plm.pdm.workflow.service.impl.TyplmWorkFlowProcessServiceImpl;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.response.ResponseResult;
import com.ty.basic.utils.ArgumentUtils;
import org.flowable.engine.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/rest/v1/feishu")
public class FeiShuController {
    @Resource
    private TyplmRedisLockService typlmRedisLockService;
    @Resource
    private TyplmWorkFlowProcessService typlmWorkFlowProcessService;
    @Resource
    public TyplmPartService typlmPartService;
    @Resource
    public TyplmEnumerationService typlmEnumerationService;
    @Resource
    private TyplmEnumerationItemService typlmEnumerationItemService;
    @Resource
    private TaskService taskService;
    @Resource
    private TyFormDataExtService tyFormDataExtService;
    @Autowired
    private TyplmEngineeringChangeService typlmEngineeringChangeService;

    public FeiShuController() {
    }

    /**
     * 飞书获取流程审批内容
     * @return
     * @throws IOException
     */
    @RequestMapping("/loadAppId")
    public ResponseResult loadAppId() {
        FeiShuCommonService feiShuCommonService = SpringUtil.getBean(FeiShuCommonService.class);
        Map<String,Object> map=new HashMap<>();
        map.put("title","飞书应用配置");
        List<Map<String,Object>> list=feiShuCommonService.selectFiguration(map);
        return ResponseResult.success(list);

    }
    /**
     * 飞书获取流程审批内容
     * @param map
     * @return
     * @throws IOException
     */
    @RequestMapping("/approvalContent")
    public ResponseResult approvalContent(@RequestBody Map<String,Object> map) throws IOException {
        String taskId= (String) map.get("taskId");
        String initiate= (String) map.get("initiate");
        String workFlowContainerId= (String) map.get("workFlowContainerId");

        if("0".equals(initiate)==false){
            FlowTaskInfo flowTaskInfo=this.typlmWorkFlowProcessService.getTaskDetailView(taskId);
            WorkFlowContainerView workFlowContainerView = flowTaskInfo.getWorkFlowContainerView();
            if (workFlowContainerView instanceof WorkFlowObjectPackage){
                WorkFlowObjectPackage workFlowObjectPackage= (WorkFlowObjectPackage) workFlowContainerView;
                List<JSONObject> list=new ArrayList<>();
                EnumerationQueryVO enumerationQueryVO=new EnumerationQueryVO();
                enumerationQueryVO.setSystem(0);
                List<EnumerationValueDTO> enumList=this.typlmEnumerationService.getEnumerationDefList(enumerationQueryVO);
                for(int i=0;i<workFlowObjectPackage.getFlowObjectList().size();i++){
                    FlowObject flowObject=workFlowObjectPackage.getFlowObjectList().get(i);
                    BigInteger oid = flowObject.getRefObjectOid();
                    String oType = flowObject.getRefObjectOtype();
                    if("ty.inteplm.part.CTyPart".equals(oType)==false) continue;
                    PartDetailsVO partDetailsVO = this.typlmPartService.queryPartDetails(oid, oType);
                    JSONObject obj=JSONObject.parseObject(JSONObject.toJSONString(partDetailsVO));
                    Map<String, List<String>> attrs=partDetailsVO.getIbaAttributeMap();
                    for(int y=0;y<enumList.size();y++){
                        if("ERP物料属性".equals(enumList.get(y).getName())){
                            if(attrs.containsKey("物料属性")){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                String attrStr=attrs.get("物料属性").get(0);
                                for(int a=0;a<items.size();a++){
                                    if(attrStr.equals(items.get(a).getInternalName())){
                                        obj.put("物料属性",items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }
                        }
                        else{
                            if(attrs.containsKey(enumList.get(y).getName())){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                String attrStr=attrs.get(enumList.get(y).getName()).get(0);
                                for(int a=0;a<items.size();a++){
                                    if(attrStr.equals(items.get(a).getInternalName())){
                                        obj.put(enumList.get(y).getName(),items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }

                        }
                    }
                    for(Map.Entry<String,List<String>> entity: attrs.entrySet()){
                        if(obj.containsKey(entity.getKey())==false){
                            List<String> attrList=entity.getValue();
                            obj.put(entity.getKey(),attrList.get(0));
                        }
                    }

                    enumerationQueryVO.setSystem(1);
                    enumList=this.typlmEnumerationService.getEnumerationDefList(enumerationQueryVO);
                    for(int y=0;y<enumList.size();y++){
                        if("来源".equals(enumList.get(y).getDisplayName())){
                            String source=obj.getString("source");
                            if(source!=null){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                for(int a=0;a<items.size();a++){
                                    if(source.equals(items.get(a).getInternalName())){
                                        obj.put(enumList.get(y).getDisplayName(),items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }
                        }
                        else if("装配模式".equals(enumList.get(y).getDisplayName())){
                            String assemblyMode=obj.getString("assemblyMode");
                            if(assemblyMode!=null){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                for(int a=0;a<items.size();a++){
                                    if(assemblyMode.equals(items.get(a).getInternalName())){
                                        obj.put(enumList.get(y).getDisplayName(),items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }
                        }
                        else if("是否成品".equals(enumList.get(y).getDisplayName())){
                            String phantom=obj.getString("phantom");
                            if(phantom!=null){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                for(int a=0;a<items.size();a++){
                                    if(phantom.equals(items.get(a).getInternalName())){
                                        obj.put(enumList.get(y).getDisplayName(),items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }
                        }
                        else if("可配置模块".equals(enumList.get(y).getDisplayName())){
                            String genericType=obj.getString("genericType");
                            if(genericType!=null){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                for(int a=0;a<items.size();a++){
                                    if(genericType.equals(items.get(a).getInternalName())){
                                        obj.put(enumList.get(y).getDisplayName(),items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }
                        }

                    }

                    list.add(obj);
                }
                Map<String,Object> rMap=new HashMap<>();
                rMap.put("list",list);
                rMap.put("router",flowTaskInfo.getRouterList());

                return ResponseResult.success(rMap);
            }
        }
        else{
            TyplmWorkFlowContainerService typlmWorkFlowContainerService=SpringUtil.getBean(TyplmWorkFlowContainerService.class);
            WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
            if (workFlowContainerView instanceof WorkFlowObjectPackage){
                WorkFlowObjectPackage workFlowObjectPackage= (WorkFlowObjectPackage) workFlowContainerView;
                List<JSONObject> list=new ArrayList<>();
                EnumerationQueryVO enumerationQueryVO=new EnumerationQueryVO();
                enumerationQueryVO.setSystem(0);
                List<EnumerationValueDTO> enumList=this.typlmEnumerationService.getEnumerationDefList(enumerationQueryVO);
                for(int i=0;i<workFlowObjectPackage.getFlowObjectList().size();i++){
                    FlowObject flowObject=workFlowObjectPackage.getFlowObjectList().get(i);
                    BigInteger oid = flowObject.getRefObjectOid();
                    String oType = flowObject.getRefObjectOtype();
                    if("ty.inteplm.part.CTyPart".equals(oType)==false) continue;
                    PartDetailsVO partDetailsVO = this.typlmPartService.queryPartDetails(oid, oType);
                    JSONObject obj=JSONObject.parseObject(JSONObject.toJSONString(partDetailsVO));
                    Map<String, List<String>> attrs=partDetailsVO.getIbaAttributeMap();
                    for(int y=0;y<enumList.size();y++){
                        if("ERP物料属性".equals(enumList.get(y).getName())){
                            if(attrs.containsKey("物料属性")){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                String attrStr=attrs.get("物料属性").get(0);
                                for(int a=0;a<items.size();a++){
                                    if(attrStr.equals(items.get(a).getInternalName())){
                                        obj.put("物料属性",items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }
                        }
                        else{
                            if(attrs.containsKey(enumList.get(y).getName())){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                String attrStr=attrs.get(enumList.get(y).getName()).get(0);
                                for(int a=0;a<items.size();a++){
                                    if(attrStr.equals(items.get(a).getInternalName())){
                                        obj.put(enumList.get(y).getName(),items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }

                        }
                    }
                    for(Map.Entry<String,List<String>> entity: attrs.entrySet()){
                        if(obj.containsKey(entity.getKey())==false){
                            List<String> attrList=entity.getValue();
                            obj.put(entity.getKey(),attrList.get(0));
                        }
                    }

                    enumerationQueryVO.setSystem(1);
                    enumList=this.typlmEnumerationService.getEnumerationDefList(enumerationQueryVO);
                    for(int y=0;y<enumList.size();y++){
                        if("来源".equals(enumList.get(y).getDisplayName())){
                            String source=obj.getString("source");
                            if(source!=null){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                for(int a=0;a<items.size();a++){
                                    if(source.equals(items.get(a).getInternalName())){
                                        obj.put(enumList.get(y).getDisplayName(),items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }
                        }
                        else if("装配模式".equals(enumList.get(y).getDisplayName())){
                            String assemblyMode=obj.getString("assemblyMode");
                            if(assemblyMode!=null){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                for(int a=0;a<items.size();a++){
                                    if(assemblyMode.equals(items.get(a).getInternalName())){
                                        obj.put(enumList.get(y).getDisplayName(),items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }
                        }
                        else if("是否成品".equals(enumList.get(y).getDisplayName())){
                            String phantom=obj.getString("phantom");
                            if(phantom!=null){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                for(int a=0;a<items.size();a++){
                                    if(phantom.equals(items.get(a).getInternalName())){
                                        obj.put(enumList.get(y).getDisplayName(),items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }
                        }
                        else if("可配置模块".equals(enumList.get(y).getDisplayName())){
                            String genericType=obj.getString("genericType");
                            if(genericType!=null){
                                IdentifierEntity identifierEntity=new IdentifierEntity();
                                identifierEntity.setOid(enumList.get(y).getOid());
                                identifierEntity.setOtype(enumList.get(y).getOtype());
                                List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                                for(int a=0;a<items.size();a++){
                                    if(genericType.equals(items.get(a).getInternalName())){
                                        obj.put(enumList.get(y).getDisplayName(),items.get(a).getDisplayName());
                                        break;
                                    }
                                }
                            }
                        }

                    }

                    list.add(obj);
                }
                Map<String,Object> rMap=new HashMap<>();
                rMap.put("list",list);
                rMap.put("router",new ArrayList<>());

                return ResponseResult.success(rMap);
            }
        }
        return ResponseResult.success(new ArrayList<>());

    }
    /**
     * 飞书获取流程表单审批内容
     * @param map
     * @return
     * @throws IOException
     */
    @RequestMapping("/approvalFormData")
    public ResponseResult approvalFormData(@RequestBody Map<String,Object> map) throws IOException {
        String taskId= (String) map.get("taskId");
        String refObjectOid= (String) map.get("refObjectOid");
        FlowTaskInfo flowTaskInfo=this.typlmWorkFlowProcessService.getTaskDetailView(taskId);
        TyplmFormDataVO formDataVO = this.tyFormDataExtService.getFormDataDetail(new BigInteger(refObjectOid), taskId);
        WorkFlowContainerView workFlowContainerView = flowTaskInfo.getWorkFlowContainerView();
        if (workFlowContainerView instanceof WorkFlowObjectPackage){
            Map<String,Object> rMap=new HashMap<>();

            List<Router> routers=new ArrayList<>();
            for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
                if("驳回".equals(flowTaskInfo.getRouterList().get(i).getLabel())==false && "终止".equals(flowTaskInfo.getRouterList().get(i).getLabel())==false ){
                    routers.add(flowTaskInfo.getRouterList().get(i));
                }
            }
            for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
                if("驳回".equals(flowTaskInfo.getRouterList().get(i).getLabel())){
                    routers.add(flowTaskInfo.getRouterList().get(i));
                }
            }
            for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
                if("终止".equals(flowTaskInfo.getRouterList().get(i).getLabel())){
                    routers.add(flowTaskInfo.getRouterList().get(i));
                }
            }
            rMap.put("router",routers);

            String projectGrouping=formDataVO.getFormdata().getString("projectGrouping");
            if(projectGrouping!=null){
                EnumerationQueryVO enumerationQueryVO=new EnumerationQueryVO();
                enumerationQueryVO.setSystem(0);
                List<EnumerationValueDTO> enumList=this.typlmEnumerationService.getEnumerationDefList(enumerationQueryVO);
                for(int y=0;y<enumList.size();y++){
                    if("项目号代号类别".equals(enumList.get(y).getDisplayName())){
                        if(projectGrouping!=null){
                            IdentifierEntity identifierEntity=new IdentifierEntity();
                            identifierEntity.setOid(enumList.get(y).getOid());
                            identifierEntity.setOtype(enumList.get(y).getOtype());
                            List<EnumerationItemHandleVO> items=this.typlmEnumerationItemService.queryEnumerationItemByDefOid(identifierEntity);
                            for(int a=0;a<items.size();a++){
                                if(projectGrouping.equals(items.get(a).getInternalName())){
                                    formDataVO.getFormdata().put("projectGrouping",items.get(a).getDisplayName());
                                    break;
                                }
                            }
                        }
                    }
                }

            }


            rMap.put("formDataVO",formDataVO.getFormdata());

            return ResponseResult.success(rMap);
        }
        return ResponseResult.success(new ArrayList<>());

    }

    /**
     * 飞书获取流程样机变更表单审批内容
     * @param map
     * @return
     * @throws IOException
     */
    @RequestMapping("/approvalChangeFormData")
    public ResponseResult approvalChangeFormData(@RequestBody Map<String,Object> map) throws IOException {
        String taskId= (String) map.get("taskId");
        String refObjectOid= (String) map.get("refObjectOid");
        FlowTaskInfo flowTaskInfo=this.typlmWorkFlowProcessService.getTaskDetailView(taskId);
        WorkFlowContainerView workFlowContainerView = flowTaskInfo.getWorkFlowContainerView();
        refObjectOid=workFlowContainerView.getBaseObjectOid().toString();

        TyplmFlowTaskInfoDTO taskInfoDTO = (new TyplmFlowTaskInfoDTO()).setTaskId(taskId).setTaskDefKey(taskId).setEditable(false);
        ChgFormVO form = this.typlmEngineeringChangeService.getChgFormByEcIdentifierEntity(new IdentifierEntity(new BigInteger(refObjectOid), "ty.inteplm.change.CTyChangeNotice"), taskInfoDTO);



        Map<String,Object> rMap=new HashMap<>();
        List<Router> routers=new ArrayList<>();
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("驳回".equals(flowTaskInfo.getRouterList().get(i).getLabel())==false && "终止".equals(flowTaskInfo.getRouterList().get(i).getLabel())==false ){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("驳回".equals(flowTaskInfo.getRouterList().get(i).getLabel())){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("终止".equals(flowTaskInfo.getRouterList().get(i).getLabel())){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        rMap.put("router",routers);
        JSONObject formDataVO=JSONObject.parseObject(form.getFormData());

        formDataVO.put("dept",formDataVO.getString("input111017"));
        formDataVO.put("ectNumber",formDataVO.getString("input41334"));
        formDataVO.put("reason",formDataVO.getString("input77773"));
        formDataVO.put("reasonTime",formDataVO.getString("date77459"));
        JSONArray gridsubform85609=formDataVO.getJSONArray("gridsubform85609");
        JSONArray tableList=new JSONArray();

        for(int i=0;i<gridsubform85609.size();i++){
            JSONObject tableObj=new JSONObject();
            tableObj.put("name",gridsubform85609.getJSONObject(i).getString("变更内容-名称"));
            tableObj.put("number",gridsubform85609.getJSONObject(i).getString("变更内容-图纸编号"));
            tableObj.put("before",gridsubform85609.getJSONObject(i).getString("变更内容-变更前内容"));
            tableObj.put("after",gridsubform85609.getJSONObject(i).getString("变更内容-变更后内容"));
            JSONArray tableDataList=new JSONArray();
            JSONObject tableDataObj=new JSONObject();
            tableDataObj.put("name","供应商端");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("采购填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("采购填处置措施"));
            tableDataObj.put("dept","采购");
            tableDataList.add(tableDataObj);

            tableDataObj=new JSONObject();
            tableDataObj.put("name","来料检");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("质量填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("质量填处置措施"));
            tableDataObj.put("dept","质量");
            tableDataList.add(tableDataObj);

            tableDataObj=new JSONObject();
            tableDataObj.put("name","库存");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("研发填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("研发填处置措施"));
            tableDataObj.put("dept","研发");
            tableDataList.add(tableDataObj);

            tableDataObj=new JSONObject();
            tableDataObj.put("name","工艺");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("工艺填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("工艺填处置措施"));
            tableDataObj.put("dept","工艺");
            tableDataList.add(tableDataObj);

            tableObj.put("tableData",tableDataList);
            tableList.add(tableObj);
        }

        formDataVO.put("tableList",tableList);

        rMap.put("formDataVO",formDataVO);

        return ResponseResult.success(rMap);

    }
    /**
     * 飞书获取流程小批量变更表单审批内容
     * @param map
     * @return
     * @throws IOException
     */
    @RequestMapping("/approvalSmallBatchQuantityFormData")
    public ResponseResult approvalSmallBatchQuantityFormData(@RequestBody Map<String,Object> map) throws IOException {
        String taskId= (String) map.get("taskId");
        String refObjectOid= (String) map.get("refObjectOid");
        FlowTaskInfo flowTaskInfo=this.typlmWorkFlowProcessService.getTaskDetailView(taskId);
        WorkFlowContainerView workFlowContainerView = flowTaskInfo.getWorkFlowContainerView();
        refObjectOid=workFlowContainerView.getBaseObjectOid().toString();

        TyplmFlowTaskInfoDTO taskInfoDTO = (new TyplmFlowTaskInfoDTO()).setTaskId(taskId).setTaskDefKey(taskId).setEditable(false);
        ChgFormVO form = this.typlmEngineeringChangeService.getChgFormByEcIdentifierEntity(new IdentifierEntity(new BigInteger(refObjectOid), "ty.inteplm.change.CTyChangeNotice"), taskInfoDTO);



        Map<String,Object> rMap=new HashMap<>();
        List<Router> routers=new ArrayList<>();
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("驳回".equals(flowTaskInfo.getRouterList().get(i).getLabel())==false && "终止".equals(flowTaskInfo.getRouterList().get(i).getLabel())==false ){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("驳回".equals(flowTaskInfo.getRouterList().get(i).getLabel())){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("终止".equals(flowTaskInfo.getRouterList().get(i).getLabel())){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        rMap.put("router",routers);
        JSONObject formDataVO=JSONObject.parseObject(form.getFormData());

        formDataVO.put("dept",formDataVO.getString("input111017"));
        formDataVO.put("ectNumber",formDataVO.getString("input41334"));
        formDataVO.put("reason",formDataVO.getString("input77773"));
        formDataVO.put("reasonTime",formDataVO.getString("date77459"));
        JSONArray gridsubform85609=formDataVO.getJSONArray("gridsubform85609");
        JSONArray tableList=new JSONArray();

        for(int i=0;i<gridsubform85609.size();i++){
            JSONObject tableObj=new JSONObject();
            tableObj.put("name",gridsubform85609.getJSONObject(i).getString("变更内容-名称"));
            tableObj.put("number",gridsubform85609.getJSONObject(i).getString("变更内容-图纸编号"));
            tableObj.put("before",gridsubform85609.getJSONObject(i).getString("变更内容-变更前内容"));
            tableObj.put("after",gridsubform85609.getJSONObject(i).getString("变更内容-变更后内容"));
            JSONArray tableDataList=new JSONArray();
            JSONObject tableDataObj=new JSONObject();
            tableDataObj.put("name","供应商端");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("采购填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("采购填处置措施"));
            tableDataObj.put("dept","采购");
            tableDataList.add(tableDataObj);

            tableDataObj=new JSONObject();
            tableDataObj.put("name","来料检");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("质量填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("质量填处置措施"));
            tableDataObj.put("dept","质量");
            tableDataList.add(tableDataObj);

            tableDataObj=new JSONObject();
            tableDataObj.put("name","生产现场");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("PMC填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("pmc填处置措施"));
            tableDataObj.put("dept","PMC");
            tableDataList.add(tableDataObj);

            tableDataObj=new JSONObject();
            tableDataObj.put("name","工艺");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("工艺填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("工艺填处置措施"));
            tableDataObj.put("dept","工艺");
            tableDataList.add(tableDataObj);

            tableObj.put("tableData",tableDataList);
            tableList.add(tableObj);
        }

        formDataVO.put("tableList",tableList);

        rMap.put("formDataVO",formDataVO);

        return ResponseResult.success(rMap);

    }
    /**
     * 飞书获取流程设计变更表单审批内容
     * @param map
     * @return
     * @throws IOException
     */
    @RequestMapping("/designChangeFormData")
    public ResponseResult designChangeFormData(@RequestBody Map<String,Object> map) throws IOException {
        String taskId= (String) map.get("taskId");
        String refObjectOid= (String) map.get("refObjectOid");
        FlowTaskInfo flowTaskInfo=this.typlmWorkFlowProcessService.getTaskDetailView(taskId);
        WorkFlowContainerView workFlowContainerView = flowTaskInfo.getWorkFlowContainerView();
        refObjectOid=workFlowContainerView.getBaseObjectOid().toString();

        TyplmFlowTaskInfoDTO taskInfoDTO = (new TyplmFlowTaskInfoDTO()).setTaskId(taskId).setTaskDefKey(taskId).setEditable(false);
        ChgFormVO form = this.typlmEngineeringChangeService.getChgFormByEcIdentifierEntity(new IdentifierEntity(new BigInteger(refObjectOid), "ty.inteplm.change.CTyChangeNotice"), taskInfoDTO);



        Map<String,Object> rMap=new HashMap<>();
        List<Router> routers=new ArrayList<>();
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("驳回".equals(flowTaskInfo.getRouterList().get(i).getLabel())==false && "终止".equals(flowTaskInfo.getRouterList().get(i).getLabel())==false ){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("驳回".equals(flowTaskInfo.getRouterList().get(i).getLabel())){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("终止".equals(flowTaskInfo.getRouterList().get(i).getLabel())){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        rMap.put("router",routers);
        JSONObject formDataVO=JSONObject.parseObject(form.getFormData());

        formDataVO.put("dept",formDataVO.getString("提出部门"));
        formDataVO.put("ectNumber",formDataVO.getString("input41334"));
        formDataVO.put("reason",formDataVO.getString("变更原因"));
        formDataVO.put("reasonTime",formDataVO.getString("date77459"));
        JSONArray gridsubform85609=formDataVO.getJSONArray("gridsubform85609");
        JSONArray tableList=new JSONArray();

        for(int i=0;i<gridsubform85609.size();i++){
            JSONObject tableObj=new JSONObject();
            tableObj.put("name",gridsubform85609.getJSONObject(i).getString("变更内容-名称"));
            tableObj.put("number",gridsubform85609.getJSONObject(i).getString("变更内容-图纸编号"));
            tableObj.put("before",gridsubform85609.getJSONObject(i).getString("变更内容-变更前内容"));
            tableObj.put("after",gridsubform85609.getJSONObject(i).getString("变更内容-变更后内容"));
            JSONArray tableDataList=new JSONArray();
            JSONObject tableDataObj=new JSONObject();
            tableDataObj.put("name","供应商端");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("采购填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("采购填处置措施"));
            tableDataObj.put("dept","采购");
            tableDataList.add(tableDataObj);

            tableDataObj=new JSONObject();
            tableDataObj.put("name","来料检");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("质量填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("质量填处置措施"));
            tableDataObj.put("dept","质量");
            tableDataList.add(tableDataObj);


            tableDataObj=new JSONObject();
            tableDataObj.put("name","工艺");
            tableDataObj.put("number",gridsubform85609.getJSONObject(i).getString("工艺填数量"));
            tableDataObj.put("title",gridsubform85609.getJSONObject(i).getString("工艺填处置措施"));
            tableDataObj.put("dept","工艺");
            tableDataList.add(tableDataObj);

            tableObj.put("tableData",tableDataList);
            tableList.add(tableObj);
        }

        formDataVO.put("tableList",tableList);

        rMap.put("formDataVO",formDataVO);

        return ResponseResult.success(rMap);

    }
    /**
     * 飞书获取流程设计变更表单审批内容
     * @param map
     * @return
     * @throws IOException
     */
    @RequestMapping("/smallBatchChange")
    public ResponseResult smallBatchChange(@RequestBody Map<String,Object> map) throws IOException {
        String taskId= (String) map.get("taskId");
        String refObjectOid= (String) map.get("refObjectOid");
        FlowTaskInfo flowTaskInfo=this.typlmWorkFlowProcessService.getTaskDetailView(taskId);
        WorkFlowContainerView workFlowContainerView = flowTaskInfo.getWorkFlowContainerView();
        refObjectOid=workFlowContainerView.getBaseObjectOid().toString();

        TyplmFlowTaskInfoDTO taskInfoDTO = (new TyplmFlowTaskInfoDTO()).setTaskId(taskId).setTaskDefKey(taskId).setEditable(false);
        ChgFormVO form = this.typlmEngineeringChangeService.getChgFormByEcIdentifierEntity(new IdentifierEntity(new BigInteger(refObjectOid), "ty.inteplm.change.CTyChangeNotice"), taskInfoDTO);



        Map<String,Object> rMap=new HashMap<>();
        List<Router> routers=new ArrayList<>();
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("驳回".equals(flowTaskInfo.getRouterList().get(i).getLabel())==false && "终止".equals(flowTaskInfo.getRouterList().get(i).getLabel())==false ){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("驳回".equals(flowTaskInfo.getRouterList().get(i).getLabel())){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        for(int i=0;i<flowTaskInfo.getRouterList().size();i++){
            if("终止".equals(flowTaskInfo.getRouterList().get(i).getLabel())){
                routers.add(flowTaskInfo.getRouterList().get(i));
            }
        }
        rMap.put("router",routers);
        JSONObject formDataVO=JSONObject.parseObject(form.getFormData());
        JSONObject formtemplateData=JSONObject.parseObject(form.getFormtemplateData());


        formDataVO.put("dept",formDataVO.getString("input44882_申请部门"));
        formDataVO.put("ectNumber",formDataVO.getString("input50507"));
        formDataVO.put("reason",formDataVO.getString("textarea54597_变更理由"));
        formDataVO.put("reasonTime",formDataVO.getString("date61102"));

        JSONArray selectuser63843_申请人=formDataVO.getJSONArray("selectuser63843_申请人");
        if(selectuser63843_申请人!=null && selectuser63843_申请人.size()>0){
            formDataVO.put("applicant",selectuser63843_申请人.getJSONObject(0).getString("displayName"));
        }
        formDataVO.put("reasonTime",formDataVO.getString("date61102"));
        formDataVO.put("Influence",formDataVO.getString("textarea101969_其他影响机型"));

        String radio75548=formDataVO.getString("radio75548");
        JSONArray widgetList=formtemplateData.getJSONArray("widgetList");
        JSONArray cols=widgetList.getJSONObject(0).getJSONArray("cols");
        JSONArray childWidgetList=cols.getJSONObject(0).getJSONArray("widgetList");
        JSONArray rows=childWidgetList.getJSONObject(0).getJSONArray("rows");
        JSONArray childCols=rows.getJSONObject(3).getJSONArray("cols");
        JSONArray childWidgetList1=childCols.getJSONObject(0).getJSONArray("widgetList");
        JSONObject options=childWidgetList1.getJSONObject(0).getJSONObject("options");
        JSONArray optionItems=options.getJSONArray("optionItems");

        for(int a=0;a<optionItems.size();a++){
            String value=optionItems.getJSONObject(a).getString("value");
            if(value.equals(radio75548)){
                formDataVO.put("changeClassification",optionItems.getJSONObject(a).getString("label"));
                break;
            }
        }

        JSONArray gridsubform42900=formDataVO.getJSONArray("gridsubform42900");
        JSONArray tableList=new JSONArray();

        for(int i=0;i<gridsubform42900.size();i++){
            JSONObject tableObj=new JSONObject();
            tableObj.put("name",gridsubform42900.getJSONObject(i).getString("input89092_物料名称"));
            tableObj.put("number",gridsubform42900.getJSONObject(i).getString("input69026_物料编码"));
            tableObj.put("model",gridsubform42900.getJSONObject(i).getString("input66707_规格型号"));
            tableObj.put("drawing",gridsubform42900.getJSONObject(i).getString("input90173_图号"));

            tableObj.put("before",gridsubform42900.getJSONObject(i).getString("textarea18905_变更前"));
            tableObj.put("after",gridsubform42900.getJSONObject(i).getString("textarea70983_变更后"));
            JSONArray tableDataList=new JSONArray();

            JSONObject tableDataObj=new JSONObject();
            tableDataObj.put("name","1.是否需要通知客户");
            tableDataObj.put("number",gridsubform42900.getJSONObject(i).getString("市场部判定必填"));
            tableDataObj.put("title",gridsubform42900.getJSONObject(i).getString("市场部输出任务必填"));
            tableDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("市场部完成时间"));
            tableDataObj.put("dept","市场部");
            tableDataList.add(tableDataObj);
            tableDataObj=new JSONObject();
            tableDataObj.put("name","2.是否需要试验验证");
            tableDataObj.put("number",gridsubform42900.getJSONObject(i).getString("研发判定必填"));
            tableDataObj.put("title",gridsubform42900.getJSONObject(i).getString("研发部输出任务"));
            tableDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("研发部完成时间"));
            tableDataObj.put("dept","研发部");
            tableDataList.add(tableDataObj);
            tableDataObj=new JSONObject();
            tableDataObj.put("name","3.是否需要工艺验证");
            tableDataObj.put("number",gridsubform42900.getJSONObject(i).getString("工艺部判定必填1"));
            tableDataObj.put("title",gridsubform42900.getJSONObject(i).getString("工艺部输出任务必填1"));
            tableDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("工艺部完成时间1"));
            tableDataObj.put("dept","工艺部");
            tableDataList.add(tableDataObj);
            tableDataObj=new JSONObject();
            tableDataObj.put("name","4.是否涉及工装设备改造");
            tableDataObj.put("number",gridsubform42900.getJSONObject(i).getString("工艺部判定必填2"));
            tableDataObj.put("title",gridsubform42900.getJSONObject(i).getString("工艺部输出任务必填2"));
            tableDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("工艺部完成时间2"));
            tableDataObj.put("dept","工艺部");
            tableDataList.add(tableDataObj);
            tableDataObj=new JSONObject();
            tableDataObj.put("name","5.是否需要供应商配合");
            tableDataObj.put("number",gridsubform42900.getJSONObject(i).getString("采购部判定必填1"));
            tableDataObj.put("title",gridsubform42900.getJSONObject(i).getString("采购部输出任务必填1"));
            tableDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("采购部完成时间1"));
            tableDataObj.put("dept","采购部");
            tableDataList.add(tableDataObj);
            tableDataObj=new JSONObject();
            tableDataObj.put("name","6.是否影响物料的需求计划");
            tableDataObj.put("number",gridsubform42900.getJSONObject(i).getString("采购判定必填2"));
            tableDataObj.put("title",gridsubform42900.getJSONObject(i).getString("采购部判定必填2"));
            tableDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("采购部完成时间2"));
            tableDataObj.put("dept","采购部");
            tableDataList.add(tableDataObj);
            tableDataObj=new JSONObject();
            tableDataObj.put("name","7.是否影响产品的交付计划");
            tableDataObj.put("number",gridsubform42900.getJSONObject(i).getString("制造中心判定必填"));
            tableDataObj.put("title",gridsubform42900.getJSONObject(i).getString("制造中心输出任务必填"));
            tableDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("制造中心完成时间"));
            tableDataObj.put("dept","制造中心");
            tableDataList.add(tableDataObj);

            tableObj.put("tableData",tableDataList);


            JSONArray InfluenceList=new JSONArray();

            JSONObject InfluenceDataObj=new JSONObject();
            InfluenceDataObj.put("name","原材料库");
            JSONArray checkbox99868=gridsubform42900.getJSONObject(i).getJSONArray("checkbox99868");
            if(checkbox99868.size()>0 && "1".equals(checkbox99868.getString(0))){
                InfluenceDataObj.put("checked",true);
            }
            else{
                InfluenceDataObj.put("checked",false);
            }

            InfluenceDataObj.put("number",gridsubform42900.getJSONObject(i).getString("input20285"));
            InfluenceDataObj.put("title",gridsubform42900.getJSONObject(i).getString("textarea35780"));
            InfluenceDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date86575"));
            InfluenceDataObj.put("dept","仓储物流部");
            InfluenceList.add(InfluenceDataObj);
            InfluenceDataObj=new JSONObject();
            InfluenceDataObj.put("name","在制产线");
            JSONArray checkbox62799=gridsubform42900.getJSONObject(i).getJSONArray("checkbox62799");
            if(checkbox62799.size()>0 && "1".equals(checkbox62799.getString(0))){
                InfluenceDataObj.put("checked",true);
            }
            else{
                InfluenceDataObj.put("checked",false);
            }

            InfluenceDataObj.put("number",gridsubform42900.getJSONObject(i).getString("input63405"));
            InfluenceDataObj.put("title",gridsubform42900.getJSONObject(i).getString("textarea48779"));
            InfluenceDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date49212"));
            InfluenceDataObj.put("dept","制造中心");
            InfluenceList.add(InfluenceDataObj);
            InfluenceDataObj=new JSONObject();
            InfluenceDataObj.put("name","半成品库");
            JSONArray checkbox9856=gridsubform42900.getJSONObject(i).getJSONArray("checkbox9856");
            if(checkbox9856.size()>0 && "1".equals(checkbox9856.getString(0))){
                InfluenceDataObj.put("checked",true);
            }
            else{
                InfluenceDataObj.put("checked",false);
            }


            InfluenceDataObj.put("number",gridsubform42900.getJSONObject(i).getString("input84889"));
            InfluenceDataObj.put("title",gridsubform42900.getJSONObject(i).getString("textarea103219"));
            InfluenceDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date38914"));
            InfluenceDataObj.put("dept","制造中心");
            InfluenceList.add(InfluenceDataObj);
            InfluenceDataObj=new JSONObject();
            InfluenceDataObj.put("name","成品库");
            JSONArray checkbox28648=gridsubform42900.getJSONObject(i).getJSONArray("checkbox28648");
            if(checkbox28648.size()>0 && "1".equals(checkbox28648.getString(0))){
                InfluenceDataObj.put("checked",true);
            }
            else{
                InfluenceDataObj.put("checked",false);
            }


            InfluenceDataObj.put("number",gridsubform42900.getJSONObject(i).getString("input95387"));
            InfluenceDataObj.put("title",gridsubform42900.getJSONObject(i).getString("textarea90403"));
            InfluenceDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date25689"));
            InfluenceDataObj.put("dept","制造中心");
            InfluenceList.add(InfluenceDataObj);
            InfluenceDataObj=new JSONObject();
            InfluenceDataObj.put("name","供应商现场");
            JSONArray checkbox67411=gridsubform42900.getJSONObject(i).getJSONArray("checkbox67411");
            if(checkbox67411.size()>0 && "1".equals(checkbox67411.getString(0))){
                InfluenceDataObj.put("checked",true);
            }
            else{
                InfluenceDataObj.put("checked",false);
            }


            InfluenceDataObj.put("number",gridsubform42900.getJSONObject(i).getString("input21865"));
            InfluenceDataObj.put("title",gridsubform42900.getJSONObject(i).getString("textarea35577"));
            InfluenceDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date82740"));
            InfluenceDataObj.put("dept","采购部");
            InfluenceList.add(InfluenceDataObj);
            InfluenceDataObj=new JSONObject();
            InfluenceDataObj.put("name","在途原材料");

            JSONArray checkbox9372=gridsubform42900.getJSONObject(i).getJSONArray("checkbox9372");
            if(checkbox9372.size()>0 && "1".equals(checkbox9372.getString(0))){
                InfluenceDataObj.put("checked",true);
            }
            else{
                InfluenceDataObj.put("checked",false);
            }
            InfluenceDataObj.put("number",gridsubform42900.getJSONObject(i).getString("input96348"));
            InfluenceDataObj.put("title",gridsubform42900.getJSONObject(i).getString("textarea18091"));
            InfluenceDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date40807"));
            InfluenceDataObj.put("dept","采购部");
            InfluenceList.add(InfluenceDataObj);
            InfluenceDataObj=new JSONObject();
            InfluenceDataObj.put("name","客户现场");

            JSONArray checkbox105525=gridsubform42900.getJSONObject(i).getJSONArray("checkbox105525");
            if(checkbox105525.size()>0 && "1".equals(checkbox105525.getString(0))){
                InfluenceDataObj.put("checked",true);
            }
            else{
                InfluenceDataObj.put("checked",false);
            }
            InfluenceDataObj.put("number",gridsubform42900.getJSONObject(i).getString("input98201"));
            InfluenceDataObj.put("title",gridsubform42900.getJSONObject(i).getString("textarea13268"));
            InfluenceDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date47741"));
            InfluenceDataObj.put("dept","市场部");
            InfluenceList.add(InfluenceDataObj);
            InfluenceDataObj=new JSONObject();
            InfluenceDataObj.put("name","在途成品");

            JSONArray checkbox42687=gridsubform42900.getJSONObject(i).getJSONArray("checkbox42687");
            if(checkbox42687.size()>0 && "1".equals(checkbox42687.getString(0))){
                InfluenceDataObj.put("checked",true);
            }
            else{
                InfluenceDataObj.put("checked",false);
            }
            InfluenceDataObj.put("number",gridsubform42900.getJSONObject(i).getString("input29724"));
            InfluenceDataObj.put("title",gridsubform42900.getJSONObject(i).getString("textarea111943"));
            InfluenceDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date108294"));
            InfluenceDataObj.put("dept","市场部");
            InfluenceList.add(InfluenceDataObj);

            tableObj.put("InfluenceList",InfluenceList);


            JSONArray changList=new JSONArray();

            JSONObject changDataObj=new JSONObject();


            JSONArray childWidgetList2=cols.getJSONObject(0).getJSONArray("widgetList");
            JSONArray childWidgetList3=childWidgetList2.getJSONObject(3).getJSONArray("widgetList");
            JSONArray clos1=childWidgetList3.getJSONObject(0).getJSONArray("cols");
            JSONArray widgetListObj=clos1.getJSONObject(5).getJSONArray("widgetList");

            JSONArray tabs=widgetListObj.getJSONObject(2).getJSONArray("tabs");
            JSONArray childWidgetList4=tabs.getJSONObject(2).getJSONArray("widgetList");

            JSONArray clos2=childWidgetList4.getJSONObject(0).getJSONArray("cols");
            JSONArray childWidgetList5=clos2.getJSONObject(0).getJSONArray("widgetList");
            JSONArray clos3=childWidgetList5.getJSONObject(2).getJSONArray("cols");
            JSONArray childWidgetList6=clos3.getJSONObject(0).getJSONArray("widgetList");

            JSONObject options1=childWidgetList6.getJSONObject(0).getJSONObject("options");
            JSONArray optionItems1=options1.getJSONArray("optionItems");

            JSONArray checkbox81782=gridsubform42900.getJSONObject(i).getJSONArray("checkbox81782");
            for(int a=0;a<optionItems1.size();a++){
                String value=optionItems1.getJSONObject(a).getString("value");
                for(int y=0;y<checkbox81782.size();y++){
                    if(value.equals(checkbox81782.getString(y))){
                        optionItems1.getJSONObject(a).put("checked",true);
                        break;
                    }
                }
            }

            changDataObj.put("checkList",optionItems1);


            changDataObj.put("number",gridsubform42900.getJSONObject(i).getString("textarea31500"));
            changDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date104235"));
            changDataObj.put("dept","研发部");
            changList.add(changDataObj);

            changDataObj=new JSONObject();

            JSONArray cols33=childWidgetList5.getJSONObject(3).getJSONArray("cols");
            JSONArray widgetListObj1=cols33.getJSONObject(0).getJSONArray("widgetList");


            JSONObject options2=widgetListObj1.getJSONObject(0).getJSONObject("options");
            JSONArray optionItems2=options2.getJSONArray("optionItems");

            JSONArray checkbox22084=gridsubform42900.getJSONObject(i).getJSONArray("checkbox22084");
            for(int a=0;a<optionItems2.size();a++){
                String value=optionItems2.getJSONObject(a).getString("value");
                for(int y=0;y<checkbox22084.size();y++){
                    if(value.equals(checkbox22084.getString(y))){
                        optionItems2.getJSONObject(a).put("checked",true);
                        break;
                    }
                }
            }

            changDataObj.put("checkList",optionItems2);


            changDataObj.put("number",gridsubform42900.getJSONObject(i).getString("textarea32471"));
            changDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date38736"));
            changDataObj.put("dept","工艺部");
            changList.add(changDataObj);

            changDataObj=new JSONObject();
            JSONArray cols44=childWidgetList5.getJSONObject(4).getJSONArray("cols");
            JSONArray widgetListObj2=cols44.getJSONObject(0).getJSONArray("widgetList");
            JSONObject options3=widgetListObj2.getJSONObject(0).getJSONObject("options");
            JSONArray optionItems3=options3.getJSONArray("optionItems");
            JSONArray checkbox95880=gridsubform42900.getJSONObject(i).getJSONArray("checkbox95880");
            for(int a=0;a<optionItems3.size();a++){
                String value=optionItems3.getJSONObject(a).getString("value");
                for(int y=0;y<checkbox95880.size();y++){
                    if(checkbox95880.get(y) instanceof String){
                        if(value.equals(checkbox95880.getString(y))){
                            optionItems3.getJSONObject(a).put("checked",true);
                            break;
                        }
                    }
                    else if(checkbox95880.get(y) instanceof Integer){
                        if(value.equals(checkbox95880.getInteger(y).toString())){
                            optionItems3.getJSONObject(a).put("checked",true);
                            break;
                        }
                    }
                }
            }
            changDataObj.put("checkList",optionItems3);
            changDataObj.put("number",gridsubform42900.getJSONObject(i).getString("textarea21627"));
            changDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date46657"));
            changDataObj.put("dept","质量管理部");
            changList.add(changDataObj);

            changDataObj=new JSONObject();
            JSONArray cols55=childWidgetList5.getJSONObject(5).getJSONArray("cols");
            JSONArray widgetListObj5=cols55.getJSONObject(0).getJSONArray("widgetList");
            JSONObject options5=widgetListObj5.getJSONObject(0).getJSONObject("options");
            JSONArray optionItems5=options5.getJSONArray("optionItems");
            JSONArray checkbox71203=gridsubform42900.getJSONObject(i).getJSONArray("checkbox71203");
            for(int a=0;a<optionItems5.size();a++){
                String value=optionItems5.getJSONObject(a).getString("value");
                for(int y=0;y<checkbox71203.size();y++){
                    if(checkbox71203.get(y) instanceof String){
                        if(value.equals(checkbox71203.getString(y))){
                            optionItems5.getJSONObject(a).put("checked",true);
                            break;
                        }
                    }
                    else if(checkbox71203.get(y) instanceof Integer){
                        if(value.equals(checkbox71203.getInteger(y).toString())){
                            optionItems5.getJSONObject(a).put("checked",true);
                            break;
                        }
                    }
                }
            }
            changDataObj.put("checkList",optionItems5);
            changDataObj.put("number",gridsubform42900.getJSONObject(i).getString("textarea28687"));
            changDataObj.put("endTime",gridsubform42900.getJSONObject(i).getString("date53538"));
            changDataObj.put("dept","采购部");
            changList.add(changDataObj);

            tableObj.put("changList",changList);

            tableList.add(tableObj);
        }

        formDataVO.put("tableList",tableList);

        rMap.put("formDataVO",formDataVO);

        return ResponseResult.success(rMap);

    }



    /**
     * 飞书获取流程设计变更表单审批内容
     * @param map
     * @return
     * @throws IOException
     */
    @RequestMapping("/getFeishuTaskId")
    public ResponseResult getFeishuTaskId(@RequestBody Map<String,Object> map) throws IOException {
        FeiShuCommonService feiShuCommonService = SpringUtil.getBean(FeiShuCommonService.class);
        Map<String,Object> rMap=new HashMap<>();
        List<Map<String,Object>> feishuCodeList=feiShuCommonService.getFeiShuApprovalCode(map);
        if(feishuCodeList.size()>0){
            String plmUserJsonStr= (String) feishuCodeList.get(0).get("task_id");
            JSONObject plmUserJson=JSONObject.parseObject(plmUserJsonStr);
            String plmUserId= (String) map.get("plmUserId");
            rMap.put("taskId",plmUserJson.getString(plmUserId));
        }
        return ResponseResult.success(rMap);

    }

    @RequestMapping("/completeTask")
    public ResponseResult completeTask(@RequestBody Map<String,Object> map) throws IOException {
        String taskId= (String) map.get("taskId");
        String approval_code= (String) map.get("approval_code");
        String nextNode = (String) map.get("nextNode");
        String plmUserId = (String) map.get("plmUserId");

        FlowTaskInfo flowTaskInfo=this.typlmWorkFlowProcessService.getTaskDetailView(taskId);
        if(flowTaskInfo.getRouterList()!=null && flowTaskInfo.getRouterList().size()==1){
            List<String> routerCheckList=new ArrayList<>();
            routerCheckList.add(flowTaskInfo.getRouterList().get(0).getValue());
            flowTaskInfo.setRouterCheckList(routerCheckList);
        }
        WorkFlowContainerView workFlowContainerView=flowTaskInfo.getWorkFlowContainerView();
        JSONObject viewObject=JSONObject.parseObject(JSONObject.toJSONString(workFlowContainerView));
        viewObject.put("codeNumber",workFlowContainerView.getCode());
        viewObject.put("delFileIdList",new JSONArray());



        Timestamp updatestamp=new Timestamp(workFlowContainerView.getUpdatestamp().getTime());
        Timestamp createTime=new Timestamp(workFlowContainerView.getCreateTime().getTime());

        Instant instant = updatestamp.toInstant();
        Instant instant1 = createTime.toInstant();

        LocalDateTime updatestampDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        LocalDateTime createTimeDateTime = LocalDateTime.ofInstant(instant1, ZoneId.systemDefault());

        // 创建一个DateTimeFormatter对象，指定格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        // 格式化LocalDateTime对象
        String formattedDate = updatestampDateTime.format(formatter);
        String formattedDate1 = createTimeDateTime.format(formatter);

        viewObject.put("updatestamp",formattedDate);
        viewObject.put("createTime",formattedDate1);
        flowTaskInfo.setViewObject(viewObject);
        if(nextNode!=null){
            List<String> check=new ArrayList<>();
            check.add(nextNode);
            flowTaskInfo.setRouterCheckList(check);
        }

        this.taskService.setVariable(taskId,"approval_code",approval_code);
        this.taskService.setVariable(taskId,"taskId",taskId);
        this.taskService.setVariable(taskId,"plmUserId",plmUserId);

        ArgumentUtils.checkArgumentNull(flowTaskInfo.getTaskId(), "taskId");
        String key = "adapter:lock:workflow:" + taskId;
        boolean hasLocked = this.typlmRedisLockService.hasLocked(key);
        if (hasLocked) {
            return ResponseResult.fail(WorkFlowErrorCodeEnum.TASK_DO_NOT_SUBMIT_REPEATEDLY.getException(new Object[0]));
        } else {
            try {
                this.typlmRedisLockService.lock(key);
                this.typlmWorkFlowProcessService.completeTask(flowTaskInfo, new ArrayList<>());
            } finally {
                this.typlmRedisLockService.unlock(key);
            }

            return ResponseResult.success(true);
        }
    }

}
